//
//  ViewController.m
//  Sqlite
//
//  Created by 周成龙 on 2017/10/15.
//  Copyright © 2017年 周成龙. All rights reserved.
//

#import "ViewController.h"

#import "DBManager.h"

#import "MainModel.h"

#import "FMDBManager.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
}

- (IBAction)add:(id)sender {
    NSArray *datas = @[
  @{@"sid": @"1111", @"img_url": @[@"aaaaa", @"bbbbb", @"cccccc"], @"alert_time": @"1500001100"},
  @{@"sid": @"2222", @"img_url": @[@"aaaaa", @"cccccc"], @"alert_time": @"1500001100"},
  @{@"sid": @"3333", @"img_url": @[@"aaaaa"], @"alert_time": @"1500001100"},
  @{@"sid": @"4444", @"img_url": @[], @"alert_time": @"1500001100"},
  @{@"sid": @"5555", @"img_url": @[@"aaaaa", @"bbbbb", @"cccccc", @"dddddd"], @"alert_time": @"1500001100"}
                       ];
    
    for (NSDictionary *d in datas) {
        MainModel *model = [[MainModel alloc] init];
        model.sid = d[@"sid"];
        model.img_url = d[@"img_url"];
        model.alert_time = d[@"alert_time"];
        model.status = @"1";
        [[FMDBManager shareManager] saveObject:model];
    }
}

- (IBAction)delete:(id)sender {
    NSArray *array = [[FMDBManager shareManager] getAllItemsFromTable];
    MainModel *model = array[0];
    [[FMDBManager shareManager] deleteObjectById:model.sid];
}

- (IBAction)update:(id)sender {
    
    
    MainModel *model = [[MainModel alloc] init];
    model.sid = @"6666";
    model.alert_time = @"123455";
    model.status = @"1";
    model.img_url = @[@"aaaaa", @"bbbbb", @"cccccc", @"dddddd", @"55555.jpg"];
    
    [[FMDBManager shareManager] updateObjectById:model];
}

- (IBAction)query:(id)sender {
    NSArray *array = [[FMDBManager shareManager] getAllItemsFromTable];
    
    for (MainModel *model in array) {
        NSLog(@"%@", model.img_url);
    }
}

- (IBAction)queryOne:(id)sender {
    MainModel *model = [[FMDBManager shareManager] getObjectById:@"5555"];
    NSLog(@"%@", model.img_url);
}

- (IBAction)deletable:(id)sender {
    [[FMDBManager shareManager] clearTable];
}

@end
